package com.hymjweb.demo.hymj.native_bill_manage.pull_cost.mapper;

import com.hymjweb.demo.hymj.native_bill_manage.pull_cost.bean.BNativeBillPullCostPojo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface BNativeBillPullCostMapper {

    class BNativeBillPullCostMapperProvider{

        public String insert(BNativeBillPullCostPojo bNativeBillPullCostPojo) {
            String sql = new SQL() {{
                INSERT_INTO("b_native_bill_pull_cost");
                VALUES("id","#{id}");
                VALUES("master_bill_id","#{masterBillId}");
                VALUES("master_bill_type_id","#{masterBillTypeId}");
                VALUES("native_bill_id","#{nativeBillId}");
                VALUES("native_pull_dispose_id","#{nativePullDisposeId}");
                VALUES("cost_share_standard","#{costShareStandard}");
                VALUES("cost_share_percent","#{costSharePercent}");
                VALUES("cost_share_amount","#{costShareAmount}");

                VALUES("create_time", "#{createTime}");
                VALUES("create_user_id", "#{createUserId}");
                VALUES("update_time", "#{updateTime}");
                VALUES("update_user_id", "#{updateUserId}");
            }}.toString();
            return sql;
        }

        public String update(BNativeBillPullCostPojo bNativeBillPullCostPojo){
            String sql= new SQL() {{
                UPDATE("b_native_bill_pull_cost t");
                SET("t.master_bill_id = #{masterBillId}");
                SET("t.master_bill_type_id = #{masterBillTypeId}");
                SET("t.native_bill_id = #{nativeBillId}");
                SET("t.native_pull_dispose_id = #{nativePullDisposeId}");
                SET("t.cost_share_standard = #{costShareStandard}");
                SET("t.cost_share_percent = #{costSharePercent}");
                SET("t.cost_share_amount = #{costShareAmount}");

                SET("t.update_time = #{updateTime}");
                SET("t.update_user_id = #{updateUserId}");

                WHERE("t.id = #{id}");
            }}.toString();
            return sql;
        }

        public String queryListByMasterBillId(String masterBillId){
            String sql= new SQL() {{
                SELECT("t.* ");
                FROM("b_native_bill_pull_cost t");
                WHERE("t.master_bill_id = #{masterBillId}");
            }}.toString();
            return sql;
        }

        public String deleteByMasterBillId(String masterBillId){
            String sql = new SQL() {{
                DELETE_FROM("b_native_bill_pull_cost t");
                WHERE("t.master_bill_id = #{masterBillId}");
            }}.toString();
            return sql;
        }

    }


    /**
     * id
     * master_bill_id
     * master_bill_type_id
     * native_bill_id
     * native_pull_dispose_id
     * cost_share_standard
     * cost_share_percent
     * cost_share_amount
     * create_time
     * create_user_id
     * update_time
     * update_user_id
     * @param masterBillId
     * @return
     */
    @Results(id = "bNativeBillPullCostPojoId",value = {
            @Result(column = "id", property = "id"),
            @Result(column = "master_bill_id", property = "masterBillId"),
            @Result(column = "master_bill_type_id", property = "masterBillTypeId"),
            @Result(column = "native_bill_id", property = "nativeBillId"),
            @Result(column = "native_pull_dispose_id", property = "nativePullDisposeId"),
            @Result(column = "cost_share_standard", property = "costShareStandard"),
            @Result(column = "cost_share_percent", property = "costSharePercent"),
            @Result(column = "cost_share_amount", property = "costShareAmount"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "create_user_id", property = "createUserId"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "update_user_id", property = "updateUserId")
    })
    @SelectProvider(type = BNativeBillPullCostMapperProvider.class, method = "queryListByMasterBillId")
    List<BNativeBillPullCostPojo> queryListByMasterBillId(String masterBillId);

    @InsertProvider(type = BNativeBillPullCostMapperProvider.class, method = "insert")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(BNativeBillPullCostPojo bNativeBillPullCostPojo);


    @UpdateProvider(type = BNativeBillPullCostMapperProvider.class, method = "update")
    int update(BNativeBillPullCostPojo bNativeBillPullCostPojo);

    @DeleteProvider(type = BNativeBillPullCostMapperProvider.class, method = "deleteByMasterBillId")
    int deleteByMasterBillId(String masterBillId);

}
